﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ExamStrategy.Question;

namespace ExamStrategy.Answer
{
    class Edward : IExamStrategy
    {
        private static int Compare(Score score1, Score score2)
        {
            if (score1.value == score2.value)
            {
                if (score1.time == score2.time) return 0;
                if (score1.time > score2.time)
                    return -1;
                else
                    return 1;
            }
            else if ((score1.time / score1.value) > (score2.time / score2.value))
            {
                return 1;
            }
            else
                return -1;
            //else return score1.time > score2.time ? -1 : 1;
        }

        //times,values
        List<Score> scorelist = new List<Score>();

        public int GetMaxScore(int[] values, int[] times)
        {
            try
            {
                if (values.Length > 32 || times.Length > 32 || times.Length < 1 || values.Length < 1) throw new Exception();
                for (int i = 0; i < times.Length; i++)
                {
                    Score score = new Score();
                    score.time = times[i];
                    score.value = values[i];
                    scorelist.Add(score);
                }
                scorelist.Sort(Compare);

                int timecount = 0;
                int currentvalue = 0;
                foreach (Score currentscore in scorelist)
                {
                    timecount += currentscore.time;
                    if (timecount > 100) break;
                    currentvalue += currentscore.value;
                }
                return currentvalue;

            }
            catch
            {

            }
            return -1;
        }
    }

    public struct Score
    {
        public int time { get; set; }
        public int value { get; set; }

    }


}

